<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Map" %>
<%@ page import="com.atguigu.Person" %>
<%@ page import="com.atguigu.servlet.Person" %>


<%--
  Created by IntelliJ IDEA.
  User: 24044
  Date: 2021/6/3
  Time: 18:18
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<% //往四个域中都保存了相同的 key 的数据。
    request.setAttribute("key", "request");
    session.setAttribute("key", "session");
    application.setAttribute("key", "application");
    pageContext.setAttribute("key", "pageContext");
%>
${ key }
<br/>

<%
    Person person = new Person();
    person.setName("国哥好帅！");
    person.setPhones(new String[]{"18610541354","18688886666","18699998888"});
    List<String> cities = new ArrayList<String>();
    cities.add("北京");
    cities.add("上海");
    cities.add("深圳");
    person.setCities(cities);
    Map<String,Object> map = new HashMap<>();
    map.put("key1","value1");
    map.put("key2","value2");
    map.put("key3","value3");
    person.setMap(map);
    pageContext.setAttribute("p", person);
%>
输出 com.atguigu.Person：${ p }<br/>
输出 com.atguigu.Person 的 name 属性：${p.name} <br>
输出 com.atguigu.Person 的 pnones 数组属性值：${p.phones[2]} <br>
输出 com.atguigu.Person 的 cities 集合中的元素值：${p.cities} <br>
输出 com.atguigu.Person 的 List 集合中个别元素值：${p.cities[2]} <br>
输出 com.atguigu.Person 的 Map 集合: ${p.map} <br>
输出 com.atguigu.Person 的 Map 集合中某个 key 的值: ${p.map.key3} <br>
输出 com.atguigu.Person 的 age 属性：${p.age} <br>
<br/>

<%
    // 1、值为 null 值的时候，为空
    request.setAttribute("emptyNull", null);
    // 2、值为空串的时候，为空
    request.setAttribute("emptyStr", "");
    // 3、值是 Object 类型数组，长度为零的时候
    request.setAttribute("emptyArr", new Object[]{});
    // 4、list 集合，元素个数为零
    List<String> list = new ArrayList<>();
    list.add("abc");
    request.setAttribute("emptyList", list);
    // 5、map 集合，元素个数为零
    Map<String,Object> map2 = new HashMap<String, Object>();
    map2.put("key1", "value1");
    request.setAttribute("emptyMap", map2);
%>
${ empty emptyNull } <br/>
${ empty emptyStr } <br/>
${ empty emptyArr } <br/>
${ empty emptyList } <br/>
${ empty emptyMap } <br/>

</body>
</html>
